/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package client;

import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import entity.*;
import session.*;
import session.nowaRemote;

public class nowaClient {

	private static nowaRemote dao;

	public static void main(String [] args) {
		try {
			System.out.println("Start Klienta...");
			Context jndiContext = getInitialContext();
                        
                        System.out.println("Start Klienta..1");
			Object ref = jndiContext.lookup("nowa/nowaBean/remote");
			System.out.println("Start Klienta..2");
                      dao = (nowaRemote)
				PortableRemoteObject.narrow(ref,nowaRemote.class);
System.out.println("Start Klienta..3");
			Users user = new Users("Jan", "Kowalski","jan@kowalski");
			String id = dao.createUser(user);
			System.out.println("Utworzenie nowego klienta id = "+id);

			//klient = new Klient("Andrzej", "Nowak");
			//id = dao.createKlient(klient);
			//System.out.println("Utworzenie nowego klienta id = "+id);

			System.out.println("Usuniecie klienta o id = 2");
			dao.removeUser("Jan");
			System.out.println("Pobranie klienta o id = 1");
			user = dao.findUser("admin");
			System.out.println("login: "+user.getUName());
			System.out.println("haslo: "+user.getUPass());
			System.out.println("mail: "+user.getUEmail());
			System.out.println("");
			System.out.println("-----------------------------------");
			System.out.println("Utworzenie rezerwacji dla klienta o id = 1");
			Accounts rez = new Accounts("1234-7654-9876");
                        rez.setUName(user);
			dao.createAccount(rez);
			System.out.println("Pobranie rezerwacji o id = 1");
			rez = dao.findAccount("1234-7654-9876");
			System.out.println("Id: "+rez.getId());
			System.out.println("Opis: "+rez.getUName());
			System.out.println("Cena "+rez.getSaldo());
			System.out.println("");
			System.out.println("-----------------------------------");
			System.out.println("Koniec programu");
		}
		catch(Exception exc) {
			System.out.println(exc);
		}
	}
	public static Context getInitialContext()
			throws NamingException {

		Properties p = new Properties( );
		p.put(Context.INITIAL_CONTEXT_FACTORY,
			"org.jnp.interfaces.NamingContextFactory");
		p.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
		p.put(Context.PROVIDER_URL,"jnp://localhost:1099");
		return new InitialContext(p);
	}
}
